package net.neocat.tcx.file;

/**
 * Created with IntelliJ IDEA.
 * User: jschek
 * Date: 4/24/13
 * Time: 11:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class CoursePoint {
    private final String name;
    private final long timestamp;
    private final TrackPoint relatedTrackPoint;
    private final GeoPosition position;
    private final PointType pointType;
    private final String notes;

    public CoursePoint(String name, long timestamp, TrackPoint relatedTrackPoint, GeoPosition position, PointType pointType, String notes) {

        this.name = name;
        this.timestamp = timestamp;
        this.relatedTrackPoint = relatedTrackPoint;
        this.position = position;
        this.pointType = pointType;
        this.notes = notes;
    }

    public CoursePoint createCoursePointWithTimestamp(long newTimestamp) {
        if(timestamp==newTimestamp) {
            return this;
        }
        return new CoursePoint(name,newTimestamp,relatedTrackPoint,position,pointType,notes);
    }

    public CoursePoint createCoursePointAt(GeoPosition newGeoPosition) {
        if(newGeoPosition.equals(position)) {
            return this;
        }
        return new CoursePoint(name,timestamp,relatedTrackPoint,newGeoPosition,pointType,notes);
    }

    @Override
    public String toString() {
        return "CoursePoint{" +
                "name='" + name + '\'' +
                ", timestamp=" + timestamp +
                ", relatedTrackPoint=" + relatedTrackPoint +
                ", position=" + position +
                ", pointType=" + pointType +
                ", notes='" + notes + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CoursePoint that = (CoursePoint) o;

        if (timestamp != that.timestamp) return false;
        if (!name.equals(that.name)) return false;
        if (notes != null ? !notes.equals(that.notes) : that.notes != null) return false;
        if (pointType != that.pointType) return false;
        if (!position.equals(that.position)) return false;
        if (!relatedTrackPoint.equals(that.relatedTrackPoint)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
        result = 31 * result + relatedTrackPoint.hashCode();
        result = 31 * result + position.hashCode();
        result = 31 * result + pointType.hashCode();
        result = 31 * result + (notes != null ? notes.hashCode() : 0);
        return result;
    }

    public String getName() {
        return name;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public TrackPoint getRelatedTrackPoint() {
        return relatedTrackPoint;
    }

    public GeoPosition getPosition() {
        return position;
    }

    public PointType getPointType() {
        return pointType;
    }

    public String getNotes() {
        return notes;
    }
}
